package com.ruoyi.project.newhope.user.controller;

import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.newhope.user.domain.NewHopeUser;
import com.ruoyi.project.newhope.user.service.INewHopeUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户Controller
 * 
 * @author ruoyi
 * @date 2021-02-08
 */
@Controller
@RequestMapping("/api/newhope/user")
public class NewHopeUserController extends BaseController
{

    @Autowired
    private INewHopeUserService newHopeUserService;

    /**
     * 查询用户列表
     */
    @GetMapping("/list")
    @ResponseBody
    public TableDataInfo list(NewHopeUser newHopeUser)
    {
        startPage();
        List<NewHopeUser> list = newHopeUserService.selectNewHopeUserList(newHopeUser);
        return getDataTable(list);
    }

    /**
     * 新增保存用户
     */
    @Log(title = "用户", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(@RequestBody NewHopeUser newHopeUser)
    {
        return toAjax(newHopeUserService.insertNewHopeUser(newHopeUser));
    }

    /**
     * 修改用户
     */
    @GetMapping("/edit/{id}")
    @ResponseBody
    public NewHopeUser edit(@PathVariable("id") Long id)
    {
        NewHopeUser newHopeUser = newHopeUserService.selectNewHopeUserById(id);
        return newHopeUser;
    }

    /**
     * 修改保存用户
     */
    @Log(title = "用户", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(@RequestBody NewHopeUser newHopeUser)
    {
        return toAjax(newHopeUserService.updateNewHopeUser(newHopeUser));
    }

    /**
     * 删除用户
     */
    @Log(title = "用户", businessType = BusinessType.DELETE)
    @GetMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String id)
    {
        return toAjax(newHopeUserService.deleteNewHopeUserByIds(id));
    }
}
